/*
 * @Author: gezhigang
 * @Date: 2020-05-25 13:18:56
 */
export const getDdevice = function() :any {
    var ua = navigator.userAgent;
    //android终端
    var isAndroid = ua.indexOf('Android') > -1 || ua.indexOf('Adr') > -1; 
    //ios终端
    var isiOS = !!ua.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
    return {
        isAndroid: isAndroid,
        isiOS: isiOS
    }
}
/**
 * @param params 判断是否是字符串类型
 */
export function isString(params: any): boolean {
    return Object.prototype.toString.call(params) === '[object String]'
}
/**
 * 
 * @param params 
 */
export function isArray(params: any): boolean {
    return Object.prototype.toString.call(params) === '[object Array]'
}
/**
 * @param params 判断是否是函数
 */
export function isFunction(params: any): boolean {
    return Object.prototype.toString.call(params) === '[object Function]'
}
/**
 * @param params 判断是否是数值类型
 */
export function isNumber(params: any): boolean {
    return Object.prototype.toString.call(params) === '[object Number]'
}
/**
 * @param params 判断是否是对象
 */
export function isObject(params: any): boolean {
    return Object.prototype.toString.call(params) === '[object Object]'
}
/**
 * @param params 判断是否是空对象
 */
export function isEmptyObject(params: any): boolean {
    return !Object.keys(params).length
}
/**
 * 随机不重复id
 */
export const guid = (): string => {
    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
        var r = Math.random() * 16 | 0,
            v = c == 'x' ? r : (r & 0x3 | 0x8)
        return v.toString(16)
    }).toUpperCase()
}
/**
 * 获取url中参数
 * @param variable 
 */
export function getQueryVariable (variable: string): any{
    const reg = new RegExp('(^|&)' + variable + '=([^&]*)(&|$)', 'i')
    const url = window.location.href
    const search = url.substring(url.lastIndexOf('?') + 1)
    const r = search.match(reg)
    if (r != null) return unescape(r[2])
    return false;
}
/**
 * 字符串解析html空格和换行
 */
export function textarea2Html(str: any) {
    return isString(str) ? str.replace(/ /g,"&nbsp;").split('\n').join('<br/>') : ''
}

export function dateFormat(date: Date ,fmt: string) {
    let o:any = {
        "M+": date.getMonth() + 1, //月份
        "d+": date.getDate(), //日
        "h+": date.getHours(), //小时
        "m+": date.getMinutes(), //分
        "s+": date.getSeconds(), //秒
        "q+": Math.floor((date.getMonth() + 3) / 3), //季度
        "S": date.getMilliseconds() //毫秒
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (let k in o)
        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}

export function getToken() {
    return ''
}